package com.example.yk_fx.video;

import androidx.lifecycle.MutableLiveData;

import com.example.yk_fx.base.BaseViewModel;
import com.example.yk_fx.entity.PlEntity;
import com.example.yk_fx.entity.ResultEntity;
import com.example.yk_fx.entity.VideoEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class VideoViewModel extends BaseViewModel<VideoRepo> {
    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
    public MutableLiveData<VideoEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> fail = new MutableLiveData<>();

    public void video(int page,int size){
        repo.video(page,size,success,fail);
    }

    public MutableLiveData<ResultEntity> loveSucc = new MutableLiveData<>();
    public MutableLiveData<String> loveFail = new MutableLiveData<>();
    public void love(int videoId){
        repo.love(videoId,loveSucc,loveFail);
    }
    public MutableLiveData<ResultEntity> noloveSucc = new MutableLiveData<>();
    public MutableLiveData<String> noloveFail = new MutableLiveData<>();
    public void nolove(int videoId){
        repo.nolove(videoId,noloveSucc,noloveFail);
    }

    public MutableLiveData<PlEntity> getSucc = new MutableLiveData<>();
    public MutableLiveData<String> getFail = new MutableLiveData<>();
    public void getPl(int videoId){
        repo.getPl(videoId,getSucc,getFail);
    }

    public MutableLiveData<PlEntity> sendSucc = new MutableLiveData<>();
    public MutableLiveData<String> sendFail = new MutableLiveData<>();
    public void sendPl(String msg,int videoId){
        Map<String,String> map = new HashMap<>();
        map.put("msg",msg);
        map.put("videoId",videoId+"");
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),s);
        repo.sendPl(body,sendSucc,sendFail);
    }

}
